<?php
namespace app\api\controller;

use app\api\logic\ApiLogic;
use app\api\logic\DoaLogic;
//基础控制器
class Doa extends Base{
	protected $middleware = ['keyCheck'];//参数验证，是否登录验证
	//获取余额
	function getBlance(){
		$data = [];
		$data['user_name'] = $this->member_info['user_name'];
		$data['total_amount'] = $this->member_info['total_amount'];
		$data['email'] = $this->member_info['email'];
		return ApiLogic::return($this->lang,0,'', $data);
	}

	//获取国家列表
	function getCountrys(){
		$rs = DoaLogic::init()->getCountrys();
		return ApiLogic::return($this->lang,0,'', $rs);
	}
	//根据国家获取服务列表
	function getServices(){
		$country_id = input('country_id', 0);
		if(!$country_id){
			return ApiLogic::return($this->lang,1003,'', []);
		}

		$params = [];
        $params['country_id'] = $this->country_id;
        $params['channel_id'] = $this->channel_id;
        $params['server_id'] = $this->server_id;
        $params['lang'] = $this->lang;
        $params['country_code'] = $this->country_code;
        $params['server_code'] = $this->server_code;
        $params['item_exchange_rate'] = $this->item_exchange_rate;
        $params['item_base_rate'] = $this->item_base_rate;
        $params['is_ok'] = $this->is_ok;
        $params['currency_symbol'] = $this->currency_symbol;
    	$data = DoaLogic::init()->getServices($params, $this->baseInfo);
    	// echo '<pre>';
    	// print_r($data);
        if(!$data){
            return ApiLogic::return($this->lang, '2000', '', []);
        }
    	return ApiLogic::return($this->lang, 0,'', $data);
	}
	//购买服务
	function buyService(){
		$country_id = input('country_id', 0);
		$server_id = input('server_id', 0);
		// echo '<pre>';
		// print_r($this);
		if(!$country_id){
			return ApiLogic::return($this->lang,1003,'', []);
		}
		if(!$server_id){
			return ApiLogic::return($this->lang,1004,'', []);
		}
		
		$params = [];
        $params['country_id']   = $this->country_id;
        $params['channel_id']   = $this->channel_id;
        $params['server_id']    = $this->server_id;
        $params['lang']         = $this->lang;
        $params['country_code'] = $this->country_code;
        $params['server_code']  = $this->server_code;
        $params['item_exchange_rate'] = $this->item_exchange_rate;
        $params['item_base_rate']   = $this->item_base_rate;
        $params['is_ok']            = $this->is_ok;
        $params['currency_symbol']  = $this->currency_symbol;
        $params['exchange_rate']    = $this->exchange_rate;
        $params['total_amount']     = $this->total_amount;

		$rs = DoaLogic::init()->buyService($params, $this->baseInfo, $this->member_info);
		if($rs['code']!=0){
            return ApiLogic::return($this->lang, $rs['code']);
        }
        $data = $rs['data'];
        $order_sn = $data['order_sn'];
        return ApiLogic::return($this->lang, 0, '', ['order_sn'=>$order_sn]);
	}

	//释放
	function denial(){
		$order_sn = input('order_sn', '');
        $rs = DoaLogic::init()->denial($order_sn, $this->member_id);
        if($rs['code']!=0){
            return ApiLogic::return($this->lang, $rs['code'],'',$rs['data']);
        }
        return ApiLogic::return($this->lang, 0);
	}

	//拉黑
	function ban(){
		$order_sn = input('order_sn', '');
        $rs = DoaLogic::init()->ban($order_sn, $this->member_id);
        if($rs['code']!=0){
            return ApiLogic::return($this->lang, $rs['code'],'',$rs['data']);
        }
        return ApiLogic::return($this->lang, 0);
	}

	//获取购买订单列表
    function getOrderList(){
        // echo $this->member_id;
        $rs = DoaLogic::init()->getOrderList($this->lang, $this->member_id, $this->exchange_rate);
        // echo '<pre>';
        // print_r($rs);
        if($rs['code']!=0){
            return ApiLogic::return($this->lang, $rs['code']);
        }
        return ApiLogic::return($this->lang, 0,'', $rs['data']);
    }

    //短信二次购买
    function buySmsSecond(){
        $rs = DoaLogic::init()->buySmsSecond($this->lang, $this->member_id);
        if($rs['code']!=0){
            $msg = isset($rs['msg'])?$rs['msg']:'';
            return ApiLogic::return($this->lang, $rs['code'], $msg);
        }
        $data = $rs['data'];
        $order_sn = $data['order_sn'];
        return ApiLogic::return($this->lang, 0, '', ['order_sn'=>$order_sn]);
    }

    //获取订单信息
    function getPhoneAndSms(){
    	$rs = DoaLogic::init()->getPhoneAndSms($this->lang, $this->member_id);
    	// echo '<pre>';
    	// print_r($rs);
        if($rs['code']!=0){
            $msg = isset($rs['msg'])?$rs['msg']:'';
            return ApiLogic::return($this->lang, $rs['code'], $msg);
        }
        return ApiLogic::return($this->lang, 0,'', $rs['data']);
    }
}